#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <fstream>
#include <algorithm>
#include <iterator>

int count_lines(const std::string & filename)
{
    std::ifstream in(filename);
    //从流的当前位置统计换行符，直到文件的末尾
    return std::count(std::istreambuf_iterator<char>(in),
    std::istreambuf_iterator<char>(),
    '\n');
}

std::vector<int> count_lines_in_files(const std::vector<std::string>& files)
{
    std::vector<int> results(files.size());
    //对输入范围内的每个元素应用一个函数，并将结果存储在另一个。
    std::transform(files.cbegin(), files.cend(), results.begin(), count_lines);
    return results;
}

int main(int argc, char *argv[])
{
    auto results = count_lines_in_files({"main.cpp", "Makefile"});

    for (auto result: results) {
        std::cout << result << " line(s)\n";
    }

    return 0;
}